var menu = new Array();
var comContainer;
var page;
var onMenuLoad = function(){
	$.ajax({
		url:'menuController.showMenu.do',
		method:'POST',
		dataType:"JSON",
		success:function(e){
			console.log(e);
			/*menu = eval("("+e+")");*/
			menu = e;
			console.log(menu);
			var container = $("#menuList1");
			comContainer = container;
			showMenu(container,1);
		},
		  error: function(XMLHttpRequest, textStatus, errorThrown) {
              alert(XMLHttpRequest.status);
              alert(XMLHttpRequest.readyState);
              alert(textStatus);
          }

	
	});
	
}

var showMenu = function(container,typeIndex){
	var htm = "";
	
	for(var i = 0;i<menu.length;i++){
		htm += "<ul class='nav nav-list'>";
		if(menu[i].parentId == '0' && menu[i].typeIndex==typeIndex){
 			htm+=
				"<li title="+menu[i].title+" >" +
					"<a href='javascript:void(0);' onclick='onMenuItemClick("+menu[i].id+")'>" +
						"<i class='"+menu[i].icon+"'></i>" +
						"<span class='menu-text'>"+menu[i].title+"</span>" +
					"</a>" +
					"<b></b>" +
				"</li>";
		}
	htm += "</ul>";
	}
	htm += "<div class='sidebar-toggle sidebar-collapse' id='sidebar-collapse'><i id='sidebar-toggle-icon' class='ace-icon fa fa-angle-double-left ace-save-state' data-icon1='ace-icon fa fa-angle-double-left' data-icon2='ace-icon fa fa-angle-double-right'></i></div>";
	container.append(htm);
	container.css("display","block");
}

var changeMenu = function(num){
	if(comContainer){
		comContainer.empty();
	}
	var container = $("#menuList"+num);
	comContainer = container;
	showMenu(container,num);
}

var onMenuItemClick = function(menuId){
	$.ajax({
		url:'menuController.getMenuUrl.do',
		method:'POST',
		data:{id:menuId},
		success:function(e){
			$(".page-content").empty();
			$(".page-content").append(e);
		}
	});
}

